/**
 * 给定两个数组，问是否能各选K/2数使得恰好构成K排列
 * 首先将A/B之中合法的数挑出来
 * 然后将A/B之中必选的数挑出来
 * 然后检查一下即可
 */
#include <bits/stdc++.h>
using namespace std;

using llt = long long;
using vi = vector<int>;

int N;
int M;
int K;
vi A;
vi B;

bool proc(){
    set<int> hasa, hasb;
    for(auto i : A){
        if(1 <= i and i <= K){
            hasa.insert(i);
        }
    }
    for(auto i : B){
        if(1 <= i and i <= K){
            hasb.insert(i);
        }
    }

    set<int> musta, mustb;
    for(int i=1;i<=K;++i){
        if(hasb.find(i) == hasb.end()){
            if(hasa.find(i) == hasa.end()) return false;
            musta.insert(i);
        }
        if(hasa.find(i) == hasa.end()){
            // assert(hasb.count(i));
            mustb.insert(i);
        }
    }

    int target = K / 2;
    if(musta.size() > target or mustb.size() > target) return false;

    return true;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int nofkase = 1; 
    cin >> nofkase;
    while(nofkase--){
        cin >> N >> M >> K;
        A.assign(N, {});
        B.assign(M, {});
        for(auto & i : A) cin >> i;
        for(auto & i : B) cin >> i;
        cout << (proc() ? "YES" : "NO")  << "\n";      
    }
    return 0;
}